#include <string>
#include <algorithm>
using namespace std;

class Solution {
public:
    string addBinary(string a, string b) {
        int cur1 = a.size()-1,cur2=b.size()-1;
        int judge = 0;
        string ret;
        while(cur1>=0 || cur2>=0 || judge)
        {
            if(cur1>=0)
            {
                judge += a[cur1--] - '0';
            }
            if(cur2>=0)
            {
                judge += b[cur2--] - '0';
            }
            ret += judge%2 + '0';
            judge /= 2;
        }
        std::reverse(ret.begin(),ret.end());
        return ret;
    }
};